﻿using MediatR;
using W.Warehouse.Api.Application.Command.AllocationCommand;
using W.Warehouse.Repository.Interface;

namespace W.Warehouse.Api.Application.CommandHandlder.AllocationCommandHadler
{
    public class AllocationAuditCommandHandler:IRequestHandler<AllocationAuditCommand,int>
    {
        private readonly IAllocationRepository _iallocationRepository;
        public AllocationAuditCommandHandler(IAllocationRepository iallocationRepository)
        {
            _iallocationRepository = iallocationRepository;
        }

        public async Task<int> Handle(AllocationAuditCommand request, CancellationToken cancellationToken)
        {
            var list = await _iallocationRepository.GetAllAsync();
            var plist = list.Where(c => c.AllocationId == request.AllocationId).FirstOrDefault();
            if (plist != null)
            {
                plist.ExaminePeople = request.ExaminePeople;
                plist.ExamineTime = DateTime.Now;
                plist.AllocationStatus = request.AllocationStatus;
            }
            return await _iallocationRepository.UpdateAsync(plist);
        }
    }
}
